package rentcar.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import rentcar.domain.UserPrincipal;
import rentcar.repository.UserDao;
import rentcar.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userRepository;
	
	public UserPrincipal loadUserByCredentials(String login, String password) {

		UserPrincipal user = userRepository.findByCredentials(login, password);
		return user;
	}

	public UserPrincipal getUserByID(Long userId) {
		UserPrincipal user = userRepository.findById(new Long(userId));
		return user;
	}

	@Override
	public void logoutUser(Long userId) {
		// TODO Auto-generated method stub
	}

	@Override
	public List<UserPrincipal> getUsers() {
		
		List<UserPrincipal> users = userRepository.findAll();		
		return users;
	}	
	

	@Override
	public void saveUser(UserPrincipal user) {
		userRepository.save(user);
	}	

	@Override
	public void deleteUser(UserPrincipal user) {
		userRepository.delete(user);
	}
	
	@Override
	public void updateUser(UserPrincipal user) {
		userRepository.update(user);
	}	
	
	
	
}
